﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SHJunketingModel;
using SHJunketingBLL;

public partial class Admin_UserManagement_AddRoleInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) 
        {
            GetCbList();
        }
    }


    //绑定复选
    private void GetCbList() 
    {
        IList<C_Permission> list = C_PermissionManage.GetAllC_Permissions();
        this.cbPer.DataSource = list;
        this.cbPer.DataTextField = "PermissionsName";
        this.cbPer.DataValueField = "PermissionsID";
        this.cbPer.DataBind();
    }

    protected void btnEdit_Click(object sender, EventArgs e)
    {

        if (txtDesc.Text.Length < 100)
        {

            //角色名和描述
            string roleName = this.txtName.Text.Trim();

            if (C_UserRoleInfoManager.GetUserIds(roleName))
            {
                Web.CommFun.Show_Msg("已经存在相同的角色！");
            }
            else
            {
                string desc = this.txtDesc.Text.Trim();
                string permissions = "";
                //获得角色权限
                foreach (ListItem li in this.cbPer.Items)
                {
                    if (li.Selected == true)
                    {
                        permissions += li.Value + "|";
                    }
                }
                C_UserRoleInfo userRoleInfo = new C_UserRoleInfo();
                userRoleInfo.RoleName = roleName;
                userRoleInfo.Permissions = permissions;
                userRoleInfo.RoleDesc = desc;
                //添加角色
                C_UserRoleInfoManager.AddC_UserRoleInfo(userRoleInfo);

                Web.CommFun.Show_Msg("添加成功！", "UserRoleInfos.aspx");
            }
        }
        else 
        {
            Web.CommFun.Show_Msg("角色说明过长！");
        }

    }
}
